package net.virtuemed.jt808.vo.req;

import io.netty.buffer.ByteBuf;
import lombok.Data;
import net.virtuemed.jt808.util.BCDUtil;
import net.virtuemed.jt808.vo.DataPacket;
/**
 * @Author: Zpsw
 * @Date: 2019-05-15
 * @Description:位置上报包
 * @Version: 1.0
 */
@Data
public class LocationMsg extends DataPacket {

    public LocationMsg(ByteBuf byteBuf) {
        super(byteBuf);
    }

    /**
     * byte[0-3]
     */
    private int alarm; //告警信息 4字节

    /**
     * byte[4-7] 状态(DWORD(32))
     */
    private int statusField;//状态 4字节

    /**
     * byte[8-11] 纬度(DWORD(32))
     */
    private float latitude;//纬度 4字节

    /**
     * byte[12-15] 经度(DWORD(32))
     */
    private float longitude;//经度 4字节

    /**
     * byte[16-17] 高程(WORD(16)) 海拔高度，单位为米（ m）
     */
    private short elevation;//海拔高度 2字节

    /**
     * byte[18-19] 速度(WORD) 1/10km/h
     */
    private short speed; //速度 2字节

    /**
     * byte[20-21] 方向(WORD) 0-359，正北为 0，顺时针
     */
    private short direction; //方向 2字节

    /**
     * byte[22-x] 时间(BCD[6]) YY-MM-DD-hh-mm-ss
     */
    private String time; //时间 6字节BCD

    @Override
    public void parseBody() {
        ByteBuf bb = this.payload;
        this.setAlarm(bb.readInt());
        this.setStatusField(bb.readInt());
        this.setLatitude(bb.readUnsignedInt() * 1.0F / 1000000);
        this.setLongitude(bb.readUnsignedInt() * 1.0F / 1000000);
        this.setElevation(bb.readShort());
        this.setSpeed(bb.readShort());
        this.setDirection(bb.readShort());
        this.setTime(BCDUtil.toBcdTimeString(readBytes(6)));
    }
}
